import {onMounted, ref, watch} from "vue";
import http from "@/commons/utils/httpUtil";
import {useRoute} from "vue-router";

export default function useQuerySzGoodsData(filterOption) {
    // 南山港区后台数据集合
    const dbData = ref([]);
    const type = useRoute().params.type;

    // 查询深圳港货物吞吐量数据
    const querySzGoodsData = () => {
        let name = type === 'sz' ? ('\'全港合计\', \'南山港区\', \'盐田港区\', \'大铲湾港区\', \'宝安港区\', \'大鹏港区\'') : ('\'南山港区\',\'蛇口集装箱码头有限公司\',\'赤湾集装箱码头有限公司\',\'招商港务（深圳）有限公司\'');
        http.get('/large/querySzGoods/' + filterOption.time + '/' + filterOption.year + '/' + filterOption.stats + '/' + name).then((res) => {
            let isValid = res && res.data && res.data.data && res.data.data.length >= 0;
            dbData.value = isValid ? res.data.data : [];
        });
    }

    onMounted(() => {
        querySzGoodsData()
    })

    watch(filterOption, querySzGoodsData)

    return {
        querySzGoodsData,
        dbData,
    }
}